﻿//----------------------------------------------------------------
// Desc: 
// Edit: ShowLong, http://blog.csdn.net/showlong
//
// Date Created: 2009-10-15
//
// Update Date :            
//
// Copyright (c) Fuel4D (http://www.fuel4d.com), All rights reserved.
//
//----------------------------------------------------------------
#pragma once


class FAPI FUI_Combo : public FUI_Object
{
    friend class FUI_System;

    FUI_DECLARE_CLASS(FUI_Combo)

public:
    FUI_Combo(EF_UI_WIDGET_TYPE t = eUWT_Combo);
    virtual void UpdateRect();
    virtual void Render(EF_UI_RENDER_LAYER layer);
    virtual bool PtInObject(funit nX, funit nY);
    virtual bool IsChild(FUI_Object* pChild);
    virtual bool HasClip(){ return uEditInput.HasClip() || uListBox.HasClip(); }
    virtual bool IsComboOpen(){ return uListBox.IsVisible(); }
    virtual bool OnMouseMove(funit nX, funit nY);
    virtual bool OnLButtonDown(funit nX, funit nY);
    virtual bool OnLButtonUp(funit nX, funit nY);
    virtual bool SetActivate();
    virtual bool IsActivated();

    // 设置选中项项
    void SelectByText(const WCHAR* text);
    void SelectByText(const ACHAR* text);
    void SelectByIndex(int index);
    void SelectByID(DWORD id);
    // 列表点击结束
    bool DoneList(funit nX, funit nY);
    // 设置编辑框是否可以输入
    void SetCanEditInput(bool b);
    bool IsCanEditInput(){ return !uEditInput.IsReadOnly(); }

    // 取得列表数据
    FINLINE FUI_List& GetListBox(){ return uListBox; }
    // 取得编辑控件数据
    FINLINE FUI_Edit& GetEditInput(){ return uEditInput; }
    // 取得下拉按钮
    FINLINE FUI_Button& GetButton(){ return uClickDown; }

protected:
    virtual void InitUIData(FUI_Object* father, fuWidgetBase* pData, FUI_Layout* layout);
    virtual void Update();

protected:
    fuWidgetCombo* pComboData;  // 控件数据地址
    FUI_Edit   uEditInput;
    FUI_Button uClickDown;
    FUI_List   uListBox;
};